#include <nanoco.h>
#include <iostream>
using namespace std;
#include <ranges>

typedef nco::Task<int, int> tTask;

tTask co(int i)
{
    cout << "In co\n";
    for (auto i : ranges::views::iota(0, i))
        co_yield i;

    co_return i *i;
};

int main()
{
    cout << version() << endl;

    auto coroutine = co(123);

    while (1)
    {
        if (coroutine.hasReturn())
        {
            cout << "return " << coroutine.getReturn() << endl;
            break;
        }
        else if (coroutine.hasYield())
        {
            cout << "yield " << coroutine.getYield() << endl;
            coroutine.remuse();
        }
    }
    cout<<"final "<<(bool)coroutine<<endl;

    return 0;
}